from flask import Blueprint
from flask_restx import Api

from app.role_control import (
    MyAthleticsCompetitionControl,
    MyCombatMatchCompetitionControl,
    MyCommonControl,
    MySubjectControl,
    ParticipantBlueprintControl,
    SubjectManagementControl,
    SystemSubjectControl, MyCTFmathRuleControl, MyCTFmathListRuleControl, MyCTFmathFlagRuleControl,
    MyCTFLevelRuleControl, StartEnvRuleControl, StartEnvVmRuleControl, GetEnvVmStautsRuleControl,
    MyRangeVmInfosRuleControl, MyActiveRangeRuleControl, MyRangeListRuleControl, MyCTFRedBlueFlagRuleControl,
    MyCTFManualRuleControl, MyCtfRedBlueScoreRuleControl, MyCTFRedBlueListRuleControl, MyCTFRedBlueRuleControl,
    MyRedBlueRangeInfoRuleControl, MyCourseWareListRuleControl, MyCourseListRuleControl, MyCourseManageRuleControl,
    VmOperateRuleControl, VmEnterRuleControl, ChangeOwnPasswordRuleControl, MyCTFNoticeControl,
)

# 竞技比赛模块
studentAthleticsCompetition = Blueprint(
    "student_athletics_competition",
    __name__,
    url_prefix="/v1/participant",
    role_control=ParticipantBlueprintControl,
)
# 我的竞技比赛
myAthleticsCompetition = Blueprint(
    "my_athletics_competition", __name__, role_control=MyAthleticsCompetitionControl
)
studentAthleticsCompetition.register_blueprint(myAthleticsCompetition)
my_ath_comp = Api(myAthleticsCompetition)
# 我的红蓝对抗比赛
myCombatMatchCompetition = Blueprint(
    "my_combat_match_competition",
    __name__,
    role_control=MyCombatMatchCompetitionControl,
)
studentAthleticsCompetition.register_blueprint(myCombatMatchCompetition)
my_combat_match = Api(myCombatMatchCompetition)

# 课题管理模块
subjectManagement = Blueprint(
    "subject_management",
    __name__,
    url_prefix="/v1/participant",
    role_control=SubjectManagementControl,
)
# 我的课题
mySubject = Blueprint("my_subject", __name__, role_control=MySubjectControl)
subjectManagement.register_blueprint(mySubject)
my_subject = Api(mySubject)
# 系统课题
systemSubject = Blueprint("system_subject", __name__, role_control=SystemSubjectControl)
subjectManagement.register_blueprint(systemSubject)
system_subject = Api(systemSubject)

# 学生模块公共接口
studentCommon = Blueprint(
    "student_common",
    __name__,
    url_prefix="/v1/participant",
    role_control=MyCommonControl,
)
student_common = Api(studentCommon)

from . import classCenter, myMath, myRange  # isort:skip

# 我的ctf比赛
my_ath_comp.add_resource(
    myMath.MyCTFmath,
    "/mymath/ctf",
    "/mymath/ctf/<int:ctf_id>",
    role_control=MyCTFmathRuleControl,
)
# 我的ctf比赛列表分页
my_ath_comp.add_resource(
    myMath.MyCTFmathList,
    "/mymath/ctflist",
    role_control=MyCTFmathListRuleControl,
)
# 答题
my_ath_comp.add_resource(
    myMath.MyCTFmathFlag,
    "/mymath/flag",
    role_control=MyCTFmathFlagRuleControl,
)
my_ath_comp.add_resource(
    myMath.MyCTFLevel,
    "/mymath/level",
    role_control=MyCTFLevelRuleControl,
)

# 我的课程
student_common.add_resource(
    classCenter.MyCourseList,
    "/course/list",
    "/course/list/system/<int:is_system>",
    role_control=MyCourseListRuleControl,
)
student_common.add_resource(
    classCenter.MyCourseManage,
    "/course/<string:uuid>",
    "/course/system/<string:uuid>/<int:is_system>",
    role_control=MyCourseManageRuleControl,
)
# 获取课件列表
my_subject.add_resource(
    classCenter.MyCourseWareList,
    "/courseware/<string:uuid>",
    endpoint="courseware/<string:uuid>",
    role_control=MyCourseWareListRuleControl,
)

# 启动靶场环境
my_ath_comp.add_resource(
    myRange.StartEnv,
    "/course/startEnv",
    "/range/startEnv",
    role_control=StartEnvRuleControl,
)
# 开启比赛环境（启动虚拟机）
my_ath_comp.add_resource(
    myRange.StartEnvVm,
    "/range/startEnvVm",
    role_control=StartEnvVmRuleControl,
)
# 获取当前靶场活动状态
my_ath_comp.add_resource(
    myRange.GetEnvVmStauts,
    "/range/envStauts",
    "/range/envStauts/<string:resource_id>",
    role_control=GetEnvVmStautsRuleControl,
)
# 获取靶场虚拟机列表（课程）
my_ath_comp.add_resource(
    myRange.MyRangeVmInfos,
    "/course/myRangeInfos",
    "/range/myRangeInfos",
    role_control=MyRangeVmInfosRuleControl,
)
# 活动靶场
my_ath_comp.add_resource(
    myRange.MyActiveRange,
    "/myrange/activeRange",
    role_control=MyActiveRangeRuleControl,
)
# 我的靶场列表
my_ath_comp.add_resource(
    myRange.MyRangeList,
    "/myrange/list",
    role_control=MyRangeListRuleControl,
)

# 操作虚拟机
student_common.add_resource(
    myRange.VmOperate,
    "/course/vmOperate",
    role_control=VmOperateRuleControl,
)
# 进入虚拟机
student_common.add_resource(
    myRange.VmEnter,
    "/course/vmEnter",
    "/range/vmEnter",
    role_control=VmEnterRuleControl,
)
# 修改个人密码 since: 21.12.28
student_common.add_resource(
    classCenter.MemberPassword,
    "/memberPwd",
    role_control=ChangeOwnPasswordRuleControl,
)

# 红蓝对抗 flag提交接口
my_combat_match.add_resource(
    myMath.MyCTFRedBlueFlag,
    "/mymath/my_ctf_red_blue_flag",
    role_control=MyCTFRedBlueFlagRuleControl,
)
# 用户申请人工裁决并查看自己申请的裁决列表（附件下载复用原下载接口）
my_combat_match.add_resource(
    myMath.MyCTFManual,
    "/mymath/my_ctf_manual",
    "/mymath/my_ctf_manual/<int:ctf_red_blue_id>",
    role_control=MyCTFManualRuleControl,
)
# 用户查看个人及所在团队红蓝对抗成绩接口
my_combat_match.add_resource(
    myMath.MyCtfRedBlueScore,
    "/mymath/my_ctf_red_blue_score/<int:ctf_red_blue_id>",
    role_control=MyCtfRedBlueScoreRuleControl,
)
# 用户查看ctf红蓝比赛接口
my_combat_match.add_resource(
    myMath.MyCTFRedBlueList,
    "/mymath/ctf_red_blue_list",
    role_control=MyCTFRedBlueListRuleControl,
)
# 学生查看公告列表
my_combat_match.add_resource(
    myMath.MyCTFNotice,
    "/mymath/ctf_notice_list",
    role_control=MyCTFNoticeControl,
)
# 用户查看某个红蓝比赛接口
my_combat_match.add_resource(
    myMath.MyCTFRedBlue,
    "/mymath/ctf_red_blue/<int:ctf_red_blue_id>",
    role_control=MyCTFRedBlueRuleControl,
)
# 获取红蓝比赛中非审计机器靶场和虚拟机uuid，便于跳转vnc(靶场加固)
my_combat_match.add_resource(
    myRange.MyRedBlueRangeInfo,
    "/my_range/my_ctf_red_blue_range_info/<int:ctf_red_blue_id>",
    role_control=MyRedBlueRangeInfoRuleControl,
)
